#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
const int N = 1010;

int n;
vector<string> query[3];
map<string, int> mp;

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while(T--){
        for(int i = 0; i < 3; i ++){
            query[i].clear();
        }
        mp.clear();
        cin >> n;

        string str;
        for(int i = 0; i < 3; i ++){
            for(int j = 0; j < n; j ++){
                cin >> str;
                if(!mp.count(str)) mp[str] = 1;
                else mp[str] = mp[str] + 1;
                query[i].push_back(str);
            }
        }

        for(int i = 0; i < 3; i ++){
            int res = 0;
            for(int j = 0; j < n; j ++){
                str = query[i][j];
                if(mp[str] == 1) res += 3;
                else if(mp[str] == 2) res += 1;
            }
            cout << res << " ";
        }
        cout << endl;

    }
    
    return 0;
}